import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    userName: null,
    token: null,
    cartNum: 0
  },
  mutations: {
    updateUserName(state, userName) {
      state.userName = userName;
    },
    updateToken(state, token) {
      state.token = token;
    },
    updateCartNum(state, cartNum) {
      state.cartNum = cartNum;
    }
  },
  plugins: [createPersistedState({storage: window.sessionStorage})]
});
